package com.qf.mybatis;

import com.qf.mapper.GoodsMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * projectName: MyBatis_1
 *
 * @author: MaTianWei
 * time: 2021/6/24 10:36
 * description:
 */

public class MybatisSelect {
    public static void main(String[] args) throws IOException {
        //1·读取配置文件
        InputStream stream = Resources.getResourceAsStream("mybatis_config.xml");
        //2·创建sqlSessionFactoryBuilder
        SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();
        //3·创建sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = factoryBuilder.build(stream);
        //4·创建sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //5·获取mapper
        GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
        //6·调用mapper的方法
        List<Map> querys = mapper.querys();
        System.out.println("querys"+querys);
        //7·关闭资源
        sqlSession.close();
    }
    }

